<?php
/**
 * Google Code API
 *
 * @version 1.0
 * @package JoomlaTune.Framework
 * @filename google.php
 * @author Sergey M. Litvinov (smart@joomlatune.ru), Alexey N Brin (userxp@joomlaportal.ru)
 * @copyright (C) 2006-2008 by Sergey M. Litvinov (http://www.joomlatune.ru)
 * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
 * @access public
 **/

defined('_VALID_MOS') or defined('_JEXEC') or die('Direct Access to this location is not allowed.');

class JTuneGoogleAPI
{
	var api_key = '';
	
	function &getInstance( $api_key='' ) {
		static $instance;
		if(!isset( $instance ) ) {
			$instance = new JTuneGoogleAPI( $api_key );
		}
		return $instance;
	}
	
	function JTuneGoogleAPI( $api_key='' ) {
		$this->api_key = $api_key;
	}
	
	function getAPI( $api_key='' ) {
		$jtga =& JTuneGoogleAPI::getInstance( $api_key );
		return JTuneGoogleAPI::js( 'http://www.google.com/jsapi?key=', $api_key );
	} //getAPI
	
	/**
	 * OPTIONAL STRING:
	 *	callback: 
	 *		The function to call once the script has loaded. If using the Auto-loading feature, 
	 *		this must specify a function name, not a function reference.
	 *	language: 
	 *		The language in which to localize the API or API's UI controls. This is specified as a ISO639 language code.
	 *	nocss:
	 *		A boolean that tells the API whether to load any style sheets typically associated with its controls. 
	 *		A developer might set this to true if he was completely overriding all of the loaded CSS and wanted to avoid the unnecessary load.
	 * 	packages:
	 *		An array of strings specifying related packages to be read in along with the core API. 
	 *		For example, you could load "piechart" and "table" along with the Visualization API.
	 *	base_domain:
	 *		The base domain from which to load the API. For example, you could load from "ditu.google.cn" 
	 *		with the "maps" module to get the Chinese version of the Maps API.
	 *	other_params: This is an object that contains options typically only supported by a 
	 *		particular API (and usually very specific to the API). If you would typically send in a parameter 
	 *		by via a script tag for an API, you can send it in other_params instead.
	 **/
	function load( $moduleName, $moduleVersion='', $optionalSettings='' ) {
		return '
		<script type="text/javascript">
			google.load("'.$moduleName.'", "'.$moduleVersion.'"'.( ($optionalSettings) ? ', '.$optionalSettings.'' : '' ).');
		</script>
		';
	} // load
	
	function loadArs( $modules ) {
		$out[] = '<script type="text/javascript">';
		foreach( $modules as $m ) {
			$out[] = 'google.load("'.$m['moduleName'].'", "'.$m['moduleVersion'].'"'.( isset($m['optionalSettings']) ? ', '.$m['optionalSettings'].'' : '' ).');';
		}
		$out[] = '</script>';
		
		return implode( "\n", $out );
	} // loadArs
	
	function loadJQ( $api_key, $jq_ver, $ui_ver ){
		$code = '';
		$code .= JTuneGoogleAPI::getAPI( $api_key );
		$code .= '<script type="text/javascript">';
		$code .= 'google.load("jquery", "'.$jq_ver.'");'
		$code .= 'google.load("jqueryui", "'.$ui_ver.'");';
		$code .= '</script>';
		
		return $code;
	} //loadJQ
	
	function css( $path='', $file='' ) {
		$text = '<link rel="stylesheet" type="text/css" href="'.$path.$file.'"/>' . "\n";
		return $text;
	}
	
	function js( $path='', $file='' ) {
		$text = '<script type="text/javascript" src="'.$path.$file.'"></script>'."\n";
		return $text;
	}
}
?>